<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="com.liuya.base.BaseModel" %>
<%@page import="com.liuya.safe.model.SafeQuery"%>
<%@page import="com.liuya.safe.model.SafeBusinessData"%>
<%@page import="com.liuya.safe.model.SafeUserCategory"%>
<%@ page import="com.liuya.common.I18N" %>
<%
I18N i18n = I18N.getInstance();
String id = request.getParameter("id");
	BaseModel node = (BaseModel)request.getAttribute( "node" );

String name="";
String description="";
if( node instanceof SafeQuery ) {
	SafeQuery q = (SafeQuery) node;
	name=q.getName();
	description=q.getDescription();
} else if( node instanceof SafeBusinessData ) {
	SafeBusinessData bd = (SafeBusinessData) node;
	name = bd.getName();
	description=bd.getDescription();
} else if( node instanceof SafeUserCategory ) {
	SafeUserCategory uc = (SafeUserCategory) node;
	name=uc.getName();
	description=uc.getDescription();
}
%>    

<form id="createForm" action="copy.do?oper=copy" method="post">
	<input type="hidden" name="id" value="<%=id%>"/>
	<label><%=i18n.say( "Name" ) %></label>
	<input name="name" type="text" size="25" value="Copy of <%=name%>"/><br/>
	<label><%=i18n.say( "Description" ) %></label>
	<input name="description" type="text" size="25" value="Copy of <%=description%>"/><br/>
	<input type="submit" value="OK" />
</form>
<script language="javascript">
var createOptions = { 
    beforeSubmit:  beforeCreate, 
    success:       afterCopy,
    resetForm:     true
}; 

//validate
jQuery('#createForm').validate({
	rules: {
		name: {
			required: true,
			remote: {
				url: "isNameValid.do?oper=isNameValid",
	        	type: "GET",
	        	dataType: "json",
	        	data: {
	        		name: function() {
	           			return jQuery( "#createForm :input[name=name]" ).val();
	        		}
	        	}
			}
		}
	}
});

// bind form using 'ajaxForm' 
jQuery('#createForm').ajaxForm(createOptions); 
</script>